#include "testlib.h"
#include <stdio.h>
#include <iostream>
#include <math.h>

#include <set>
#include <map>
#include <vector>
#include <utility>

using namespace std;

typedef vector<int> line;
typedef vector<line> matrix;
typedef map<int, int> function;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forv(i, a) for (int i = 0; i < int(a.size()); i++)
#define mp make_pair

pair<int, int> isDiagnostic(const matrix& a) {
    forv(i, a) {
        forn(j, i) {
            if (a[i] == a[j]) {
                return mp(j, i);
            }
        }
    }
    return mp(0, 0);
}

int main(int argc, char * argv[])
{
    setName("compare that outputted functions are diagnostic");
    registerTestlibCmd(argc, argv);

    int n = inf.readInt(), m = inf.readInt();
    matrix a(n, line(m));
    set<int> s;
    forn(i, n) {
        forn(j, m) {
            a[i][j] = inf.readInt();
            s.insert(a[i][j]);
        }
    }
    vector<int> args(s.begin(), s.end());
    
    do {
        function f;
        string yes = ouf.readWord();
/*        if (yes != "Yes") {
            quitf(_wa, "Yes expected.");
        }*/
        int maxVal = ouf.readInt();
        cerr << yes << " " << maxVal << endl;
        //if (maxVal > n) quitf(_wa, "max value have to be <= n");
        forv(i, args) {
            int arg = ouf.readInt();
            if (arg != args[i]) {
                quitf(_wa, "incorrect output of function: argument "
                    "%d expected, but %d found", args[i], arg);
            }
            string sep = ouf.readWord();
            if (sep != "->") quitf(_wa, "-> separator expected, but %s found.", sep.c_str());
            int val = ouf.readInt();
            f[arg] = val;
            if (val < 0 || val > maxVal) {
                quitf(_wa, "value of function must be nonnegative and" 
                    " not greater max value = %d", maxVal);
            }
        }
        matrix b = a;
        forn(i, n) {
            forn(j, m) {
                b[i][j] = f[a[i][j]];
            }
        }
        pair<int, int> error = isDiagnostic(b);
        if (error != mp(0, 0)) {
            quitf(_wa, "line %d equal to the line %d", error.first + 1, error.second + 1);
        }
    } while (!ouf.seekEof());   
    quitf(_ok, "ok");
}
